#include "cpu/exec/template-start.h"

#define instr	cmp

extern CPU_state cpu;

static void do_execute() {
	DATA_TYPE temp = op_dest->val - op_src->val;
	uint32_t i, count = 0;
	cpu.ZF = (temp == 0);
	cpu.SF = MSB(temp);
	cpu.OF = ((MSB(op_dest->val) != MSB(op_src->val))
				&& (MSB(temp) != MSB(op_dest->val)));
	cpu.CF = (op_dest->val < op_src->val);
	cpu.AF = ((op_dest->val & 0xf) < (op_src->val & 0xf));
	temp &= 0xff;
	for (i = 0; i < 8; i++, temp >>= 1) {
		count += (temp & 0x1);
	}
	cpu.PF = (count % 2 == 0);
	
	print_asm_template2();
}

make_instr_helper(i2a)
make_instr_helper(i2rm)
make_instr_helper(r2rm)
make_instr_helper(rm2r)

#if		DATA_BYTE == 4 || DATA_BYTE == 2
make_instr_helper(si2rm)
/*make_helper(concat(cmp_i2rm_b2_, SUFFIX)) {
	int8_t i;
	uint32_t count = 0;
	DATA_TYPE_S s, temp;
	int len = 1 + concat(decode_rm_, SUFFIX)(eip + 1);
	i = instr_fetch(eip + len, 1);
	len += 1;
	s = (DATA_TYPE_S)i;
	temp = op_src->val - s;
	
	cpu.ZF = (temp == 0);
	cpu.SF = MSB(temp);
	cpu.OF = ((MSB(op_src->val) != MSB(s))
				&& (MSB(temp) != MSB(op_src->val)));
	cpu.CF = (op_src->val < s);
	cpu.AF = ((op_src->val & 0xf) < (s & 0xf));
	temp &= 0xff;
	for (i = 0; i < 8; i++, temp >>= 1) {
		count += (temp & 0x1);
	}
	cpu.PF = (count % 2 == 0);
	

	print_asm("cmp" str(SUFFIX) " $%x,%s", s, op_src->str);
	return len;
}*/
#endif

#include "cpu/exec/template-end.h"
